<template>
<div class="tool">
    <nav>
        <li v-if="top" @click="scrolltop">
            <Tooltip content="返回顶部" placement="left-start">
                 <Icon type="arrow-up-c"></Icon>
            </Tooltip>
            
        </li>
    </nav>
</div>
</template>
<script>
export default{
    data(){
        return {
            top:false
        }
    },mounted(){
        window.addEventListener('scroll',this.handleScroll);
    },methods:{
        handleScroll(e){
            //console.log(e);
            var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
            if(scrollTop>0){
                this.top=true;
            }else{
                this.top=false;
            }
        },scrolltop(){
            document.documentElement.scrollTop = document.body.scrollTop = 0;
        }
    },destroyed(){
        window.removeEventListener('scroll',this.handleScroll)
    }
}
</script>
